﻿#include "plugin2.h"

Plugin2::Plugin2()
{
	ui.setupUi(this);
	ui.tabWidget->setCurrentIndex(0);	//默认标签页
	ui.comboBox_morphTypes->addItems(
		QStringList() << "腐蚀" << "膨胀" << "开运算" << "闭运算" << "阶梯" << "顶帽" << "黑帽");
	ui.comboBox_morphShapes->addItems(
		QStringList() << "矩形" << "十字" << "椭圆");
	//标签页里的控件都会发出信号，告诉主程序调用本类内的图片处理函数
	connect(ui.spinBox_morphIter, static_cast<void (QSpinBox::*)(int)> (&QSpinBox::valueChanged), [=]() {emit updateNeeded(); });
	connect(ui.comboBox_morphTypes, static_cast<void (QComboBox::*)(int)> (&QComboBox::currentIndexChanged), [=]() {emit updateNeeded(); });
	connect(ui.comboBox_morphShapes, static_cast<void (QComboBox::*)(int)> (&QComboBox::currentIndexChanged), [=]() {emit updateNeeded(); });
}
Plugin2::~Plugin2()
{
}


QString Plugin2::title()
{
	return "插件2";
}

QString Plugin2::version()
{
	return "1.0.0基于Qt 5.15.2";
}

void Plugin2::processImage(const cv::Mat& inputImg, cv::Mat& outputImg)
{
	switch (ui.tabWidget->currentIndex())
	{
	case 0:	//形态学标签页
		cv::morphologyEx(inputImg, outputImg,
			ui.comboBox_morphTypes->currentIndex(),	//操作，腐蚀、膨胀等
			cv::getStructuringElement(ui.comboBox_morphShapes->currentIndex(), cv::Size(5, 5)),	//掩模形状与大小
			cv::Point(-1, -1),
			ui.spinBox_morphIter->value());	//迭代次数
		break;
	case 1:	//滤波标签页
		break;
	default:
		break;
	}
}